/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lab5_Test.Test3;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author THIEN
 */
public class ThreadOne implements Runnable {

    Thread t;
    Data d = new Data();

    public ThreadOne(Data d) {
        this.d = d;
        t = new Thread(this);
        t.start();
    }

    public void run() {
        //throw new UnsupportedOperationException("Not supported yet.");
        this.getData();
    }

    public void getData() {
        int i = 0;
        for (i = 0; i < 3; i++) {
            synchronized (this.d) {
                if (!d.flag) {
                    d.flag = true;
                    String[] data = d.getData();
                    d.temp = data[i];
                    d.notify();
                }
                try {
                    d.wait();
                } catch (InterruptedException ex) {
                    //Logger.getLogger(ThreadOne.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    }
}
